﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL.RF.QuantityandTime;
using Model.RF.QuantityInfo;
using System;

namespace DAL.RF.QuantityandTime
{
    public class Test_PRDepartment : ITest_PRDepartment
    {
        #region 静态变量部分
        private const string PARM_TEST_DEPARTMENT = "@Department";
        private const string PARM_TEST_STARTTIME = "@starttime";
        private const string PARM_TEST_STOPTIME = "@stoptime";
        #endregion


        #region 数据检索部分
        public IList<Department_PRInfo> GetTimeD_Department(string spname, DateTime starttime, DateTime stoptime)
        {
            IList<Department_PRInfo> t_qs = new List<Department_PRInfo>();
            SqlParameter[] testParms = GetDTParameters();
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    Department_PRInfo t_q = new Department_PRInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetDecimal(2), 
                        rdr.GetInt32(3), rdr.GetInt32(4));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<Department_PRInfo> GetTimeD_Department_TestUser(string spname, DateTime starttime, DateTime stoptime)
        {
            IList<Department_PRInfo> t_qs = new List<Department_PRInfo>();
            SqlParameter[] testParms = GetDTParameters();
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    if (!rdr.IsDBNull(2))
                    {
                        Department_PRInfo t_q = new Department_PRInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(),
                            rdr.GetValue(3).ToString(), rdr.GetDecimal(4), rdr.GetInt32(5), rdr.GetInt32(6));
                        t_qs.Add(t_q);
                    }
                }
            }
            return t_qs;
        }

        public IList<Department_PRInfo> GetTimeD_Department_DebugTestUser(string spname, string department, DateTime starttime, DateTime stoptime)
        {
            IList<Department_PRInfo> t_qs = new List<Department_PRInfo>();
            SqlParameter[] testParms = GetDepDTParameters();
            testParms[0].Value = department;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    if (!rdr.IsDBNull(1))
                    {
                        Department_PRInfo t_q = new Department_PRInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(),
                            rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetInt32(5));
                        t_qs.Add(t_q);
                    }
                }
            }
            return t_qs;
        }

        //**************************************以上公共***********************************************************************

        public IList<Department_PRInfo> GetPRbyTimeD_Department(DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department("Test_PRbyTimeD_Department", starttime, stoptime);
        }
        public IList<Department_PRInfo> GetPRbyTimeD_Department_TestUser(DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department_TestUser("Test_PRbyTimeD_Department_TestUser", starttime, stoptime);
        }
        public IList<Department_PRInfo> GetPRbyTimeD_Department_DebugTestUser(string department, DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department_DebugTestUser("Test_PRbyTimeD_Department_DebugTestUser", department, starttime, stoptime);
        }

        //**************************************以上为最终合格率，以下为一次合格率*****************

        public IList<Department_PRInfo> GetOPRbyTimeD_Department(DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department("Test_OPRbyTimeD_Department", starttime, stoptime);
        }
        public IList<Department_PRInfo> GetOPRbyTimeD_Department_TestUser(DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department_TestUser("Test_OPRbyTimeD_Department_TestUser", starttime, stoptime);
        }
        public IList<Department_PRInfo> GetOPRbyTimeD_Department_DebugTestUser(string department, DateTime starttime, DateTime stoptime)
        {
            return GetTimeD_Department_DebugTestUser("Test_OPRbyTimeD_Department_DebugTestUser", department, starttime, stoptime);
        }
        #endregion

        #region 参数部分
        private static SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)             
                };
            return parms;
        }

        private static SqlParameter[] GetDepDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_DEPARTMENT,SqlDbType.NVarChar,20),
                    new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)             
                };
            return parms;
        }
        #endregion
    }
}
